package com.nebula.api.modules.app.conctroller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.nebula.commons.modules.system.entity.SysUserLoginLog;
import com.nebula.commons.modules.system.service.SysUserLoginLogService;
import link.ahsj.core.entitys.ApiModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author Eastern unbeaten
 * @version 1.0
 * @date 2020/1/7 23:37
 * @mail chenshiyun2011@163.com
 */
@RestController
@RequestMapping("/demo")
public class DemoApi {
    @Autowired
    private SysUserLoginLogService sysUserLoginLogService;

    @GetMapping("getJson")
    public ResponseEntity<ApiModel> getJson() {
        return ResponseEntity.ok(ApiModel.data(new SysUserLoginLog()));
    }

    @GetMapping("sysUserLog")
    public ResponseEntity<ApiModel> list(Page page) {
        IPage<SysUserLoginLog> page1 = sysUserLoginLogService.page(page);
        return ResponseEntity.ok(ApiModel.data(page));
    }

    @PostMapping("sysUserLog")
    public ResponseEntity<ApiModel> save(@RequestBody SysUserLoginLog sysUserLoginLog) {
        boolean save = sysUserLoginLogService.save(sysUserLoginLog);
        return ResponseEntity.ok(ApiModel.data(save));
    }

    @PutMapping("sysUserLog")
    public ResponseEntity<ApiModel> update(@RequestBody SysUserLoginLog sysUserLoginLog) {
        boolean b = sysUserLoginLogService.updateById(sysUserLoginLog);
        return ResponseEntity.ok(ApiModel.data(b));
    }

    @DeleteMapping("sysUserLog")
    public ResponseEntity<ApiModel> delete(@RequestBody SysUserLoginLog sysUserLoginLog) {
        boolean b = sysUserLoginLogService.removeById(sysUserLoginLog);
        return ResponseEntity.ok(ApiModel.data(b));
    }


    @DeleteMapping("sysUserLog/{id}")
    public ResponseEntity<ApiModel> deleteId(@PathVariable("id") String id) {
        boolean b = sysUserLoginLogService.removeById(id);
        return ResponseEntity.ok(ApiModel.data(b));
    }
}
